//
//  UIButton+DR.m
//  DoctorRen
//
//  Created by Lemon on 2018/11/19.
//

#import "UIButton+DR.h"

@implementation UIButton (DR)
    
-(void)setHorizontalButton:(CGFloat) spacing{
    CGSize imageSize = self.imageView.frame.size;
    CGSize titleSize = self.titleLabel.frame.size;
    CGSize textSize = [self.titleLabel.text sizeWithAttributes:(@{NSFontAttributeName : self.titleLabel.font})];
    CGSize frameSize = CGSizeMake(ceilf(textSize.width), ceilf(textSize.height));
    if (textSize.width + 0.5 < frameSize.width){
        titleSize.width = frameSize.width;
    }
    CGFloat totalHeight = imageSize.height + titleSize.height + spacing;
    self.imageEdgeInsets = UIEdgeInsetsMake(-(totalHeight - imageSize.height), 0.0, 0.0, -titleSize.width);
    self.titleEdgeInsets = UIEdgeInsetsMake((self.imageView.frame.size.height), -self.imageView.frame.size.width, 0, 0);
}

@end
